package com.yangchuang.openpicture.config;
import com.yangchuang.openpicture.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    private final JwtInterceptor jwtInterceptor;

    public WebMvcConfiguration(JwtInterceptor jwtInterceptor) {
        this.jwtInterceptor = jwtInterceptor;
    }

    /**
     * 注册拦截器并配置拦截规则
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns( // todo 排除不需要拦截的路径
                        "/user/refresh-token", //刷新token的接口
                        "/user/forget-password-reset", // ⭐ 添加这一行
                        "/user/login",       // 登录接口
                        "/user/register",    // 注册接口
                        "/email/send-verify-code",  //获取email验证码接口
                        "/doc.html"    //接口文档页
                );
    }

}
